package com.ynr.user.service.impl;

import java.util.Map;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ynr.common.utils.CodeInfoEnum;
import com.ynr.common.utils.CommonResult;
import com.ynr.common.utils.ResultUtil;
import com.ynr.user.dao.IUserDao;
import com.ynr.user.service.IUserService;

@Service("userService")
public class UserServiceImpl implements IUserService {

	private static final Logger logger = LoggerFactory
			.getLogger(UserServiceImpl.class);
	
	@Autowired 
	private IUserDao userDao;

	@Override
	public CommonResult login(String email, String password) {
		try {
			UseremailPasswordToken token = new UseremailPasswordToken(email, password);
			SecurityUtils.getSubject().login(token);
	        return ResultUtil.returnSuccess(CodeInfoEnum.LOGIN_SUCCESS);
		} catch(AuthenticationException e) {
			logger.error("AuthenticationException:{}", e.toString());
			return ResultUtil.returnError(CodeInfoEnum.LOGIN_EMAIL_OR_PASSWORD_ERROR);
		}
	}

	@Override
	public CommonResult addUser(Map<String, Object> params) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public CommonResult updateUserInfo(Map<String, Object> params) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public CommonResult updateUserPassword(String userId, String password) {
		// TODO Auto-generated method stub
		return null;
	}

}